package com.sig.common.logic;

import org.apache.commons.collections.CollectionUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author sig
 * @since 2019/2/21
 */
public abstract class LogicManager<T extends Logic> {
    private Map<String, T> map = new HashMap<>();

    protected void init() {
        if (CollectionUtils.isEmpty(this.getSet()))
            return;
        for (T logic : this.getSet()) {
            String name = logic.getClass().getSimpleName();
            String type = name.substring(name.indexOf("_") + 1);
            map.put(type, logic);
        }
    }

    public T getLogic(int type) {
        return map.get(String.valueOf(type));
    }

    public T getLogic(String type) {
        return map.get(type);
    }

    protected abstract Set<T> getSet();
}
